
'use strict';
const dayjs = require("dayjs");
module.exports = app => {
    const { INTEGER, DATE, STRING, TINYINT } = app.Sequelize;
    const MemberUser = app.model.define(
      'MemberUser',
          {
            id: {
              type: INTEGER,
              primaryKey: true,
              autoIncrement: true,
            },
            phone: {
              type: STRING(20),
              allowNull: false,
              unique: true,
              comment: '手机号',
            },
            password: {
              type: STRING(255),
              allowNull: false,
              comment: '密码',
            },
            openid: {
              type: STRING(100),
              allowNull: true,
              unique: true,
              comment: '微信openid',
            },
            nickname: {
              type: STRING(50),
              allowNull: true,
              comment: '昵称',
            },
            avatar: {
              type: STRING(255),
              allowNull: true,
              comment: '头像',
            },
            gender: {
              type: TINYINT(1),
              allowNull: true,
              defaultValue: 0,
              comment: '性别：0未知，1男，2女',
            },
            points: {
              type: INTEGER,
              allowNull: true,
              defaultValue: 0,
              comment: '积分',
            },
            status: {
              type: TINYINT(1),
              allowNull: true,
              defaultValue: 1,
              comment: '状态：0禁用，1正常',
            },
            last_login_time: {
              type: DATE,
              allowNull: true,
              comment: '上次登录时间',
              get() {
                  return dayjs(this.getDataValue('last_login_time')).format('YYYY-MM-DD HH:mm:ss');
              }
            },
            create_time: {
                  type: DATE,
                  get() {
                      return dayjs(this.getDataValue('create_time')).format('YYYY-MM-DD HH:mm:ss');
                  }
            },
            update_time: {
                  type: DATE,
                  get() {
                      return dayjs(this.getDataValue('update_time')).format('YYYY-MM-DD HH:mm:ss');
                  }
              }
          },
          {
              tableName: 'member_user',
              timestamps: true, // 启用时间戳(createdAt, updatedAt)
              updatedAt: 'update_time', // 不想要 updatedAt
              createdAt: 'create_time', // 想要  createdAt 但是希望名称叫做 create_time
          }
    );
    return MemberUser;
};